unit subcontrObra;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Provider, SqlExpr, DB, DBClient, DBLocal, DBLocalS, DBCtrls,
  Grids, DBGrids, RXDBCtrl, StdCtrls, Mask, ToolEdit, DateUtils, ppVar,
  Buttons, ppCtrls, ppBands, ppPrnabl, ppClass, ppCache, ppProd, ppReport,
  ppDB, ppComm, ppRelatv, ppDBPipe, ppTypes;

type
  TfrmSubcontrObra = class(TForm)
    lblFechaIni: TLabel;
    edtFechaIni: TDateEdit;
    lblFechaFin: TLabel;
    edtFechaFin: TDateEdit;
    grdSueldos: TRxDBGrid;
    Label1: TLabel;
    Label2: TLabel;
    cargaSocial: TDBText;
    enMano: TDBText;
    Label3: TLabel;
    total: TDBText;
    cds: TSQLClientDataSet;
    cdsDENOMINACION: TStringField;
    cdsCARGA: TFloatField;
    cdsMANO: TFloatField;
    cdsSUBTOTAL: TFloatField;
    cdssubTCarga: TAggregateField;
    cdssubtMano: TAggregateField;
    cdstotal: TAggregateField;
    s: TDataSource;
    btnCargar: TButton;
    ppSubObra: TppDBPipeline;
    ppComprasMaterialppField1: TppField;
    ppComprasMaterialppField2: TppField;
    ppComprasMaterialppField3: TppField;
    ppComprasMaterialppField4: TppField;
    rpSubObra: TppReport;
    ppHeaderBand1: TppHeaderBand;
    ppDBImage1: TppDBImage;
    ppLabel8: TppLabel;
    ppEmail: TppLabel;
    ppTe: TppLabel;
    ppDBText3: TppDBText;
    ppDBText6: TppDBText;
    ppLine4: TppLine;
    ppLabel5: TppLabel;
    ppLabel6: TppLabel;
    ppLine1: TppLine;
    ppDetailBand1: TppDetailBand;
    ppLine3: TppLine;
    datMaterial: TppDBText;
    datUnitario: TppDBText;
    ppFooterBand1: TppFooterBand;
    ppLabel1: TppLabel;
    ppDBCalc1: TppDBCalc;
    ppEmpresa: TppDBPipeline;
    ppEmpresappField1: TppField;
    ppEmpresappField2: TppField;
    ppEmpresappField3: TppField;
    ppEmpresappField4: TppField;
    ppEmpresappField5: TppField;
    ppEmpresappField6: TppField;
    ppEmpresappField7: TppField;
    ppEmpresappField8: TppField;
    ppEmpresappField9: TppField;
    ppEmpresappField10: TppField;
    ppEmpresappField11: TppField;
    ppEmpresappField12: TppField;
    ppEmpresappField13: TppField;
    ppEmpresappField14: TppField;
    ppEmpresappField15: TppField;
    sEmpresa: TDataSource;
    btnVistaPrevia: TBitBtn;
    ppLabel2: TppLabel;
    ppLabel3: TppLabel;
    ppDBText1: TppDBText;
    ppDBText2: TppDBText;
    ppSystemVariable1: TppSystemVariable;
    ppLabel4: TppLabel;
    ppDBCalc2: TppDBCalc;
    ppLabel7: TppLabel;
    ppDBCalc3: TppDBCalc;
    btnExcel: TSpeedButton;
    procedure btnCargarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure grdSueldosTitleClick(Column: TColumn);
    procedure FormCreate(Sender: TObject);
    procedure btnVistaPreviaClick(Sender: TObject);
    procedure btnExcelClick(Sender: TObject);
  private
    { Private declarations }
  public
    constructor CreateNuevo(AOwner: TComponent);
  end;

var
  frmSubcontrObra: TfrmSubcontrObra;

implementation

uses Recursos;

{$R *.dfm}

constructor TfrmSubcontrObra.CreateNuevo(AOwner: TComponent);
begin
  inherited Create(Aowner);
  self.edtFechaIni.Date := IncYear(now, -1);
  self.edtFechaFin.Date := now;
  self.ShowModal;
end;

procedure TfrmSubcontrObra.btnCargarClick(Sender: TObject);
begin
  self.cds.Close;
  self.cds.Params[0].AsString := FormatDateTime('mm/dd/yy', StrToDate(self.edtFechaFin.EditText));
  self.cds.Params[1].AsString := FormatDateTime('mm/dd/yy', incDay(StrToDate(self.edtFechaIni.EditText)));
  self.cds.Open;
end;

procedure TfrmSubcontrObra.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  self.cds.Close;
end;

procedure TfrmSubcontrObra.grdSueldosTitleClick(Column: TColumn);
begin
  self.cds.IndexFieldNames := Column.FieldName;
end;

procedure TfrmSubcontrObra.FormCreate(Sender: TObject);
begin
  //acomodo(self);
end;

procedure TfrmSubcontrObra.btnVistaPreviaClick(Sender: TObject);
begin
  if (self.cds.State in [dsInactive]) then
    self.btnCargarClick(Sender);
  self.rpSubObra.DeviceType := dtScreen;
  self.rpSubObra.Print;
end;

procedure TfrmSubcontrObra.btnExcelClick(Sender: TObject);
begin
  abrirEnExcel(self, self.cds, nil, nil, 'PAGOS A SUBCONTRATISTAS POR OBRA', 'INTERVALO DEFINIDO: del '
  +DateTimeToStr(self.edtFechaIni.Date)+' al '+DateTimeToStr(self.edtFechaFin.Date));
end;

end.
